import { PureComponent } from 'react'

// 定义一个测量渲染花费的时间函数组件
function logRenderTime(OriginComponent) {
  // 返回时可以省略 类名， 返回匿名类
  return class extends PureComponent {
    UNSAFE_componentWillMount() {
      this.beginTime = new Date().getTime()
    }
    componentDidMount() {
      this.endTime = new Date().getTime()
      const interval = this.endTime - this.beginTime
      console.log(OriginComponent.name + '组件渲染需要花费' + interval + 'ms')
    }
    render() {
      return <OriginComponent {...this.props} />
    }
  }
}
export default logRenderTime
